package f.f0.f;

import com.huawei.agconnect.exception.AGCServerException;
import f.a;
import f.a0;
import f.d0;
import f.f0.g.e;
import f.f0.i.b;
import f.f0.i.g.d;
import f.g;
import f.m;
import f.p;
import f.r;
import f.s;
import f.v;
import f.w;
import f.y;
import g.f;
import g.q;
import g.t;
import g.u;
import g.z;
import java.io.IOException;
import java.lang.ref.Reference;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.Socket;
import java.net.SocketException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.net.ssl.SSLPeerUnverifiedException;

/* compiled from: RealConnection */
public final class c extends d {
    public final g b;
    public final d0 c;
    public Socket d;
    public Socket e;
    public p f;
    public w g;
    public f.f0.i.g h;
    public g.g i;
    public f j;
    public boolean k;
    public int l;
    public int m = 1;
    public final List<Reference<g>> n = new ArrayList();
    public long o = Long.MAX_VALUE;

    public c(g gVar, d0 d0Var) {
        this.b = gVar;
        this.c = d0Var;
    }

    public void a(f.f0.i.g gVar) {
        synchronized (this.b) {
            this.m = gVar.o();
        }
    }

    public void b(f.f0.i.p pVar) throws IOException {
        pVar.c(b.REFUSED_STREAM);
    }

    /* JADX WARNING: Removed duplicated region for block: B:52:0x00f4  */
    /* JADX WARNING: Removed duplicated region for block: B:51:0x00ee  */
    /* JADX WARNING: Removed duplicated region for block: B:86:0x0139 A:{SYNTHETIC, EDGE_INSN: B:86:0x0139->B:80:0x0139 ?: BREAK  } */
    /* JADX WARNING: Removed duplicated region for block: B:59:0x0105  */
    public void c(int r16, int r17, int r18, int r19, boolean r20, f.d r21, f.m r22) {
        /*
        r15 = this;
        r7 = r15;
        r8 = r21;
        r9 = r22;
        r0 = r7.g;
        if (r0 != 0) goto L_0x0147;
    L_0x0009:
        r0 = r7.c;
        r0 = r0.a;
        r1 = r0.f;
        r10 = new f.f0.f.b;
        r10.m4725init(r1);
        r2 = r0.i;
        if (r2 != 0) goto L_0x0051;
    L_0x0018:
        r0 = f.h.h;
        r0 = r1.contains(r0);
        if (r0 == 0) goto L_0x0044;
    L_0x0020:
        r0 = r7.c;
        r0 = r0.a;
        r0 = r0.a;
        r0 = r0.d;
        r1 = f.f0.j.f.a;
        r1 = r1.k(r0);
        if (r1 == 0) goto L_0x0031;
    L_0x0030:
        goto L_0x005b;
    L_0x0031:
        r1 = new f.f0.f.e;
        r2 = new java.net.UnknownServiceException;
        r3 = "CLEARTEXT communication to ";
        r4 = " not permitted by network security policy";
        r0 = c.b.a.a.a.E(r3, r0, r4);
        r2.<init>(r0);
        r1.m4727init(r2);
        throw r1;
    L_0x0044:
        r0 = new f.f0.f.e;
        r1 = new java.net.UnknownServiceException;
        r2 = "CLEARTEXT communication not enabled for client";
        r1.<init>(r2);
        r0.m4727init(r1);
        throw r0;
    L_0x0051:
        r0 = r0.e;
        r1 = f.w.H2_PRIOR_KNOWLEDGE;
        r0 = r0.contains(r1);
        if (r0 != 0) goto L_0x013a;
    L_0x005b:
        r11 = 0;
        r12 = r11;
    L_0x005d:
        r0 = r7.c;	 Catch:{ IOException -> 0x00c5 }
        r0 = r0.a();	 Catch:{ IOException -> 0x00c5 }
        if (r0 == 0) goto L_0x007d;
    L_0x0065:
        r1 = r15;
        r2 = r16;
        r3 = r17;
        r4 = r18;
        r5 = r21;
        r6 = r22;
        r1.e(r2, r3, r4, r5, r6);	 Catch:{ IOException -> 0x00c5 }
        r0 = r7.d;	 Catch:{ IOException -> 0x00c5 }
        if (r0 != 0) goto L_0x0078;
    L_0x0077:
        goto L_0x0090;
    L_0x0078:
        r1 = r16;
        r2 = r17;
        goto L_0x0084;
    L_0x007d:
        r1 = r16;
        r2 = r17;
        r15.d(r1, r2, r8, r9);	 Catch:{ IOException -> 0x00c1 }
    L_0x0084:
        r3 = r19;
        r15.f(r10, r3, r8, r9);	 Catch:{ IOException -> 0x00bf }
        r0 = r7.c;	 Catch:{ IOException -> 0x00bf }
        r0 = r0.c;	 Catch:{ IOException -> 0x00bf }
        java.util.Objects.requireNonNull(r22);	 Catch:{ IOException -> 0x00bf }
    L_0x0090:
        r0 = r7.c;
        r0 = r0.a();
        if (r0 == 0) goto L_0x00aa;
    L_0x0098:
        r0 = r7.d;
        if (r0 == 0) goto L_0x009d;
    L_0x009c:
        goto L_0x00aa;
    L_0x009d:
        r0 = new java.net.ProtocolException;
        r1 = "Too many tunnel connections attempted: 21";
        r0.<init>(r1);
        r1 = new f.f0.f.e;
        r1.m4727init(r0);
        throw r1;
    L_0x00aa:
        r0 = r7.h;
        if (r0 == 0) goto L_0x00be;
    L_0x00ae:
        r1 = r7.b;
        monitor-enter(r1);
        r0 = r7.h;	 Catch:{ all -> 0x00bb }
        r0 = r0.o();	 Catch:{ all -> 0x00bb }
        r7.m = r0;	 Catch:{ all -> 0x00bb }
        monitor-exit(r1);	 Catch:{ all -> 0x00bb }
        goto L_0x00be;
    L_0x00bb:
        r0 = move-exception;
        monitor-exit(r1);	 Catch:{ all -> 0x00bb }
        throw r0;
    L_0x00be:
        return;
    L_0x00bf:
        r0 = move-exception;
        goto L_0x00cb;
    L_0x00c1:
        r0 = move-exception;
    L_0x00c2:
        r3 = r19;
        goto L_0x00cb;
    L_0x00c5:
        r0 = move-exception;
        r1 = r16;
        r2 = r17;
        goto L_0x00c2;
    L_0x00cb:
        r4 = r7.e;
        f.f0.c.g(r4);
        r4 = r7.d;
        f.f0.c.g(r4);
        r7.e = r11;
        r7.d = r11;
        r7.i = r11;
        r7.j = r11;
        r7.f = r11;
        r7.g = r11;
        r7.h = r11;
        r4 = r7.c;
        r4 = r4.c;
        java.util.Objects.requireNonNull(r22);
        r4 = 1;
        r5 = 0;
        if (r12 != 0) goto L_0x00f4;
    L_0x00ee:
        r12 = new f.f0.f.e;
        r12.m4727init(r0);
        goto L_0x0103;
    L_0x00f4:
        r6 = r12.a;
        r13 = f.f0.c.q;
        if (r13 == 0) goto L_0x0101;
    L_0x00fa:
        r14 = new java.lang.Object[r4];	 Catch:{ IllegalAccessException | InvocationTargetException -> 0x0101, IllegalAccessException | InvocationTargetException -> 0x0101 }
        r14[r5] = r0;	 Catch:{ IllegalAccessException | InvocationTargetException -> 0x0101, IllegalAccessException | InvocationTargetException -> 0x0101 }
        r13.invoke(r6, r14);	 Catch:{ IllegalAccessException | InvocationTargetException -> 0x0101, IllegalAccessException | InvocationTargetException -> 0x0101 }
    L_0x0101:
        r12.b = r0;
    L_0x0103:
        if (r20 == 0) goto L_0x0139;
    L_0x0105:
        r10.d = r4;
        r6 = r10.c;
        if (r6 != 0) goto L_0x010c;
    L_0x010b:
        goto L_0x0135;
    L_0x010c:
        r6 = r0 instanceof java.net.ProtocolException;
        if (r6 == 0) goto L_0x0111;
    L_0x0110:
        goto L_0x0135;
    L_0x0111:
        r6 = r0 instanceof java.io.InterruptedIOException;
        if (r6 == 0) goto L_0x0116;
    L_0x0115:
        goto L_0x0135;
    L_0x0116:
        r6 = r0 instanceof javax.net.ssl.SSLHandshakeException;
        if (r6 == 0) goto L_0x0123;
    L_0x011a:
        r13 = r0.getCause();
        r13 = r13 instanceof java.security.cert.CertificateException;
        if (r13 == 0) goto L_0x0123;
    L_0x0122:
        goto L_0x0135;
    L_0x0123:
        r13 = r0 instanceof javax.net.ssl.SSLPeerUnverifiedException;
        if (r13 == 0) goto L_0x0128;
    L_0x0127:
        goto L_0x0135;
    L_0x0128:
        if (r6 != 0) goto L_0x0134;
    L_0x012a:
        r5 = r0 instanceof javax.net.ssl.SSLProtocolException;
        if (r5 != 0) goto L_0x0134;
    L_0x012e:
        r0 = r0 instanceof javax.net.ssl.SSLException;
        if (r0 == 0) goto L_0x0133;
    L_0x0132:
        goto L_0x0134;
    L_0x0133:
        r4 = 0;
    L_0x0134:
        r5 = r4;
    L_0x0135:
        if (r5 == 0) goto L_0x0139;
    L_0x0137:
        goto L_0x005d;
    L_0x0139:
        throw r12;
    L_0x013a:
        r0 = new f.f0.f.e;
        r1 = new java.net.UnknownServiceException;
        r2 = "H2_PRIOR_KNOWLEDGE cannot be used with HTTPS";
        r1.<init>(r2);
        r0.m4727init(r1);
        throw r0;
    L_0x0147:
        r0 = new java.lang.IllegalStateException;
        r1 = "already connected";
        r0.<init>(r1);
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: f.f0.f.c.c(int, int, int, int, boolean, f.d, f.m):void");
    }

    public final void d(int i, int i2, f.d dVar, m mVar) throws IOException {
        Socket createSocket;
        d0 d0Var = this.c;
        Proxy proxy = d0Var.b;
        a aVar = d0Var.a;
        if (proxy.type() == Type.DIRECT || proxy.type() == Type.HTTP) {
            createSocket = aVar.c.createSocket();
        } else {
            createSocket = new Socket(proxy);
        }
        this.d = createSocket;
        InetSocketAddress inetSocketAddress = this.c.c;
        Objects.requireNonNull(mVar);
        this.d.setSoTimeout(i2);
        try {
            f.f0.j.f.a.g(this.d, this.c.c, i);
            try {
                this.i = new u(q.e(this.d));
                this.j = new t(q.b(this.d));
            } catch (NullPointerException e) {
                if ("throw with null exception".equals(e.getMessage())) {
                    throw new IOException(e);
                }
            }
        } catch (ConnectException e2) {
            StringBuilder g = c.b.a.a.a.g("Failed to connect to ");
            g.append(this.c.c);
            ConnectException connectException = new ConnectException(g.toString());
            connectException.initCause(e2);
            throw connectException;
        }
    }

    public final void e(int i, int i2, int i3, f.d dVar, m mVar) throws IOException {
        int i4 = i2;
        y.a aVar = new y.a();
        aVar.f(this.c.a.a);
        aVar.d("CONNECT", null);
        aVar.c("Host", f.f0.c.o(this.c.a.a, true));
        aVar.c("Proxy-Connection", "Keep-Alive");
        aVar.c("User-Agent", "okhttp/3.12.1");
        y b = aVar.b();
        a0.a aVar2 = new a0.a();
        aVar2.a = b;
        aVar2.b = w.HTTP_1_1;
        aVar2.c = 407;
        aVar2.d = "Preemptive Authenticate";
        aVar2.g = f.f0.c.c;
        aVar2.k = -1;
        aVar2.l = -1;
        f.q.a aVar3 = aVar2.f;
        Objects.requireNonNull(aVar3);
        String str = "Proxy-Authenticate";
        f.q.a(str);
        String str2 = "OkHttp-Preemptive";
        f.q.b(str2, str);
        aVar3.b(str);
        aVar3.a.add(str);
        aVar3.a.add(str2);
        aVar2.b();
        Objects.requireNonNull(this.c.a.d);
        r rVar = b.a;
        int i5 = i;
        d(i, i2, dVar, mVar);
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("CONNECT ");
        stringBuilder.append(f.f0.c.o(rVar, true));
        stringBuilder.append(" HTTP/1.1");
        String stringBuilder2 = stringBuilder.toString();
        g.g gVar = this.i;
        f.f0.h.a aVar4 = new f.f0.h.a(null, null, gVar, this.j);
        g.a0 B = gVar.B();
        long j = (long) i4;
        TimeUnit timeUnit = TimeUnit.MILLISECONDS;
        B.g(j, timeUnit);
        this.j.B().g((long) i3, timeUnit);
        aVar4.k(b.c, stringBuilder2);
        aVar4.d.flush();
        aVar2 = aVar4.f(false);
        aVar2.a = b;
        a0 b2 = aVar2.b();
        long a = e.a(b2);
        if (a == -1) {
            a = 0;
        }
        z h = aVar4.h(a);
        f.f0.c.v(h, Integer.MAX_VALUE, timeUnit);
        ((f.f0.h.a.f) h).close();
        i4 = b2.c;
        if (i4 != AGCServerException.OK) {
            if (i4 == 407) {
                Objects.requireNonNull(this.c.a.d);
                throw new IOException("Failed to authenticate with proxy");
            }
            StringBuilder g = c.b.a.a.a.g("Unexpected response code for CONNECT: ");
            g.append(b2.c);
            throw new IOException(g.toString());
        } else if (!this.i.A().Q() || !this.j.A().Q()) {
            throw new IOException("TLS tunnel buffered too many bytes!");
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:41:0x0110 A:{Catch:{ all -> 0x0101 }} */
    /* JADX WARNING: Removed duplicated region for block: B:39:0x010a A:{Catch:{ all -> 0x0101 }} */
    /* JADX WARNING: Removed duplicated region for block: B:44:0x0114  */
    public final void f(f.f0.f.b r7, int r8, f.d r9, f.m r10) throws java.io.IOException {
        /*
        r6 = this;
        r9 = f.w.HTTP_1_1;
        r0 = r6.c;
        r0 = r0.a;
        r1 = r0.i;
        if (r1 != 0) goto L_0x0025;
    L_0x000a:
        r7 = r0.e;
        r10 = f.w.H2_PRIOR_KNOWLEDGE;
        r7 = r7.contains(r10);
        if (r7 == 0) goto L_0x001e;
    L_0x0014:
        r7 = r6.d;
        r6.e = r7;
        r6.g = r10;
        r6.j(r8);
        return;
    L_0x001e:
        r7 = r6.d;
        r6.e = r7;
        r6.g = r9;
        return;
    L_0x0025:
        java.util.Objects.requireNonNull(r10);
        r10 = r6.c;
        r10 = r10.a;
        r0 = r10.i;
        r1 = 0;
        r2 = r6.d;	 Catch:{ AssertionError -> 0x0103 }
        r3 = r10.a;	 Catch:{ AssertionError -> 0x0103 }
        r4 = r3.d;	 Catch:{ AssertionError -> 0x0103 }
        r3 = r3.e;	 Catch:{ AssertionError -> 0x0103 }
        r5 = 1;
        r0 = r0.createSocket(r2, r4, r3, r5);	 Catch:{ AssertionError -> 0x0103 }
        r0 = (javax.net.ssl.SSLSocket) r0;	 Catch:{ AssertionError -> 0x0103 }
        r7 = r7.a(r0);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r2 = r7.b;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        if (r2 == 0) goto L_0x0051;
    L_0x0046:
        r2 = f.f0.j.f.a;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r3 = r10.a;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r3 = r3.d;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r4 = r10.e;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r2.f(r0, r3, r4);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
    L_0x0051:
        r0.startHandshake();	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r2 = r0.getSession();	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r3 = f.p.a(r2);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r4 = r10.j;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r5 = r10.a;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r5 = r5.d;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r2 = r4.verify(r5, r2);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        if (r2 == 0) goto L_0x00b0;
    L_0x0068:
        r2 = r10.k;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10 = r10.a;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10 = r10.d;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r4 = r3.c;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r2.a(r10, r4);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r7 = r7.b;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        if (r7 == 0) goto L_0x007d;
    L_0x0077:
        r7 = f.f0.j.f.a;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r1 = r7.i(r0);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
    L_0x007d:
        r6.e = r0;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r7 = g.q.e(r0);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10 = new g.u;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10.m8406init(r7);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r6.i = r10;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r7 = r6.e;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r7 = g.q.b(r7);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10 = new g.t;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10.m8405init(r7);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r6.j = r10;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r6.f = r3;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        if (r1 == 0) goto L_0x009f;
    L_0x009b:
        r9 = f.w.a(r1);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
    L_0x009f:
        r6.g = r9;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r7 = f.f0.j.f.a;
        r7.a(r0);
        r7 = r6.g;
        r9 = f.w.HTTP_2;
        if (r7 != r9) goto L_0x00af;
    L_0x00ac:
        r6.j(r8);
    L_0x00af:
        return;
    L_0x00b0:
        r7 = r3.c;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r8 = 0;
        r7 = r7.get(r8);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r7 = (java.security.cert.X509Certificate) r7;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r8 = new javax.net.ssl.SSLPeerUnverifiedException;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r9 = new java.lang.StringBuilder;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r9.<init>();	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r1 = "Hostname ";
        r9.append(r1);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10 = r10.a;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10 = r10.d;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r9.append(r10);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10 = " not verified:\n    certificate: ";
        r9.append(r10);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10 = f.e.b(r7);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r9.append(r10);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10 = "\n    DN: ";
        r9.append(r10);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10 = r7.getSubjectDN();	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10 = r10.getName();	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r9.append(r10);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r10 = "\n    subjectAltNames: ";
        r9.append(r10);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r7 = f.f0.l.d.a(r7);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r9.append(r7);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r7 = r9.toString();	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        r8.<init>(r7);	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
        throw r8;	 Catch:{ AssertionError -> 0x00fe, all -> 0x00fc }
    L_0x00fc:
        r7 = move-exception;
        goto L_0x0112;
    L_0x00fe:
        r7 = move-exception;
        r1 = r0;
        goto L_0x0104;
    L_0x0101:
        r7 = move-exception;
        goto L_0x0111;
    L_0x0103:
        r7 = move-exception;
    L_0x0104:
        r8 = f.f0.c.t(r7);	 Catch:{ all -> 0x0101 }
        if (r8 == 0) goto L_0x0110;
    L_0x010a:
        r8 = new java.io.IOException;	 Catch:{ all -> 0x0101 }
        r8.<init>(r7);	 Catch:{ all -> 0x0101 }
        throw r8;	 Catch:{ all -> 0x0101 }
    L_0x0110:
        throw r7;	 Catch:{ all -> 0x0101 }
    L_0x0111:
        r0 = r1;
    L_0x0112:
        if (r0 == 0) goto L_0x0119;
    L_0x0114:
        r8 = f.f0.j.f.a;
        r8.a(r0);
    L_0x0119:
        f.f0.c.g(r0);
        throw r7;
        */
        throw new UnsupportedOperationException("Method not decompiled: f.f0.f.c.f(f.f0.f.b, int, f.d, f.m):void");
    }

    public boolean g(a aVar, @Nullable d0 d0Var) {
        if (this.n.size() < this.m && !this.k) {
            f.f0.a aVar2 = f.f0.a.a;
            a aVar3 = this.c.a;
            Objects.requireNonNull((v.a) aVar2);
            if (!aVar3.a(aVar)) {
                return false;
            }
            if (aVar.a.d.equals(this.c.a.a.d)) {
                return true;
            }
            if (this.h == null || d0Var == null || d0Var.b.type() != Type.DIRECT || this.c.b.type() != Type.DIRECT || !this.c.c.equals(d0Var.c) || d0Var.a.j != f.f0.l.d.a || !k(aVar.a)) {
                return false;
            }
            try {
                aVar.k.a(aVar.a.d, this.f.c);
                return true;
            } catch (SSLPeerUnverifiedException unused) {
            }
        }
        return false;
    }

    public boolean h() {
        return this.h != null;
    }

    public f.f0.g.c i(v vVar, s.a aVar, g gVar) throws SocketException {
        if (this.h != null) {
            return new f.f0.i.f(vVar, aVar, gVar, this.h);
        }
        f.f0.g.f fVar = (f.f0.g.f) aVar;
        this.e.setSoTimeout(fVar.j);
        g.a0 B = this.i.B();
        long j = (long) fVar.j;
        TimeUnit timeUnit = TimeUnit.MILLISECONDS;
        B.g(j, timeUnit);
        this.j.B().g((long) fVar.k, timeUnit);
        return new f.f0.h.a(vVar, gVar, this.i, this.j);
    }

    public final void j(int i) throws IOException {
        this.e.setSoTimeout(0);
        f.f0.i.g.c cVar = new f.f0.i.g.c(true);
        Socket socket = this.e;
        String str = this.c.a.a.d;
        g.g gVar = this.i;
        f fVar = this.j;
        cVar.a = socket;
        cVar.b = str;
        cVar.c = gVar;
        cVar.d = fVar;
        cVar.e = this;
        cVar.f = i;
        f.f0.i.g gVar2 = new f.f0.i.g(cVar);
        this.h = gVar2;
        f.f0.i.q qVar = gVar2.r;
        synchronized (qVar) {
            if (qVar.e) {
                throw new IOException("closed");
            } else if (qVar.b) {
                Logger logger = f.f0.i.q.g;
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine(f.f0.c.n(">> CONNECTION %s", f.f0.i.e.a.k()));
                }
                qVar.a.V(f.f0.i.e.a.v());
                qVar.a.flush();
            }
        }
        qVar = gVar2.r;
        f.f0.i.t tVar = gVar2.n;
        synchronized (qVar) {
            if (qVar.e) {
                throw new IOException("closed");
            }
            qVar.n(0, Integer.bitCount(tVar.a) * 6, (byte) 4, (byte) 0);
            int i2 = 0;
            while (i2 < 10) {
                if ((((1 << i2) & tVar.a) != 0 ? 1 : null) != null) {
                    int i3 = i2 == 4 ? 3 : i2 == 7 ? 4 : i2;
                    qVar.a.I(i3);
                    qVar.a.K(tVar.b[i2]);
                }
                i2++;
            }
            qVar.a.flush();
        }
        int a = gVar2.n.a();
        if (a != 65535) {
            gVar2.r.t(0, (long) (a - 65535));
        }
        new Thread(gVar2.s).start();
    }

    public boolean k(r rVar) {
        int i = rVar.e;
        r rVar2 = this.c.a.a;
        boolean z = false;
        if (i != rVar2.e) {
            return false;
        }
        if (rVar.d.equals(rVar2.d)) {
            return true;
        }
        p pVar = this.f;
        if (pVar != null && f.f0.l.d.a.c(rVar.d, (X509Certificate) pVar.c.get(0))) {
            z = true;
        }
        return z;
    }

    public String toString() {
        StringBuilder g = c.b.a.a.a.g("Connection{");
        g.append(this.c.a.a.d);
        g.append(":");
        g.append(this.c.a.a.e);
        g.append(", proxy=");
        g.append(this.c.b);
        g.append(" hostAddress=");
        g.append(this.c.c);
        g.append(" cipherSuite=");
        p pVar = this.f;
        g.append(pVar != null ? pVar.b : "none");
        g.append(" protocol=");
        g.append(this.g);
        g.append('}');
        return g.toString();
    }
}
